<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <script>


        // 第一种
        
        var arr = ['刘备', '张飞', '关羽'];
        function say(arr) {
            return arr.join("|");
        }
        console.log(say(arr));



        // 第二种

        var arr1 = ['刘备', '张飞', '关羽'];
        function yes(arr1) {
            var list = '';
            for (i = 0; i <= arr1.length - 1; i++) {
                if (i == arr1.length - 1) {
                    list = list + arr1[i];
                } else {
                    list = list + arr1[i] + '|';
                }
            }
            return list;
        }
        console.log(yes(arr1));

    </script>


</body>

</html>